<template>
	<view style="margin: 0 20upx;">
		
		<view style="height: 80upx;line-height: 80upx;color: #999999;margin-top: 20upx;">
			商户名称 : <text v-if="merchname" style="margin-left: 20upx;">{{merchname}}</text>
		</view>
		
		<view style="height: 80upx;line-height: 80upx;color: #999999;margin-top: 20upx;border-top: 1px solid #F1F1F1;border-bottom: 1px solid #F1F1F1;">
			<input type="number" v-model="num" style="margin-top: 15upx;" placeholder="请输入充值金额"/>
		</view>
		
		<button type="default" style="margin-top: 200upx;background: #F76260;color: #fff;" @click="submit">提交</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				res:[],
				openid:'',
				merchid:'',
				merchname: '',
				num:'',
			};
		},
		onLoad:function(e){
			this.merchid = e.merchid
			uni.showLoading()
			uni.getStorage({
				key: 'openid',
				success: (res) => {
					this.openid = res.data
					this.setAjax()
				},
				fail: () => {
					uni.navigateTo({
						url: '../../login/login'
					});
				}
			});
		},
		methods:{
			setAjax(){
				uni.request({
					url: 'https://app.t9y9y9.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.merch_credit2_recharge&app=1',
					method: 'POST',
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					data:{
						'openid': this.openid,
						'merchid': this.merchid
					},
					success: res => {
						this.merchname = res.data.merch.merchname
					},
					fail: () => {},
					complete: () => {}
				});
				uni.hideLoading()
			},
			submit () {
				var that = this
				console.log(this.merchid)
				uni.request({
					url: 'https://app.t9y9y9.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.merch_credit2_recharge.submit&app=1',
					method: 'POST',
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					data:{
						'openid': this.openid,
						'merchid': this.merchid,
						'money': this.num
					},
					success: res => {
						// uni.showToast({
						// 	title: res.data.result.message,
						// 	icon:'none'
						// })
						let id = res.data.result.message
						if (res.data.status == 1) {
							setTimeout(()=> {
								uni.navigateTo({
									url: './money?merchid=' + that.merchid + '&id=' + id
								})
							}, 200);
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			jump(e){
				uni.navigateTo({
					url: e.currentTarget.dataset.src
				});
			},
		}
	}
</script>

<style>
	page {
		background: #fff;
	}
</style>
